package com.jluzh10.learning.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jluzh10.learning.dao.PictureCarouselMapper;
import com.jluzh10.learning.domain.PictureCarousel;
import com.jluzh10.learning.domain.PictureCarouselExample;
import com.jluzh10.learning.service.PictureCarouselService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author yzg
 * @create 2019/5/25
 */
@Service
@Transactional
public class PictureCarouselServiceImpl implements PictureCarouselService {

    private final PictureCarouselMapper pictureCarouselMapper;

    @Autowired
    public PictureCarouselServiceImpl(PictureCarouselMapper pictureCarouselMapper) {
        this.pictureCarouselMapper = pictureCarouselMapper;
    }


    @Override
    public int add(PictureCarousel pictureCarousel) {

        return pictureCarouselMapper.insertSelective(pictureCarousel);
    }

    @Override
    public List<PictureCarousel> findByNum(Integer num) {
        PictureCarouselExample example=new PictureCarouselExample();
        //按照权重排倒序
        example.setOrderByClause("weight desc");
        //分页
        if (num!=0)
        PageHelper.startPage(1, num);

        return pictureCarouselMapper.selectByExample(example);
    }
}
